package com.example.leero.graduation.Util;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DecodeFormat;
import com.example.leero.graduation.API;
import com.example.leero.graduation.Constants;


public class ImageLoader {

  public static void load(Context context, ImageView imageView, String url) {
    url = getCorrectUrl(url);
    Glide.with(context).load(url).into(imageView);
  }

  public static void loadAsARGB_8888(Context context, ImageView imageView, String url) {
    url = getCorrectUrl(url);
    Glide.with(context)
            .load(url)
            .asBitmap()
            .format(DecodeFormat.PREFER_ARGB_8888)
            .into(imageView);
  }

  public static String getCorrectUrl(String url) {
    if (StringUtil.isEmpty(url)) {
      return url;
    }

    if (!url.startsWith("http://") && !url.startsWith("https://")) {
        url = API.BASE_SERVER + url;
    }
    return url;
  }
}
